package com.example.demo.controller;

/**
 * @description:
 * @author: xiaowu
 * @time: 2025/4/8 21:51
 */

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.example.demo.domain.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    UserMapper userMapper;

    @PostMapping("/insert")
    public Result<Object> insert(@RequestBody  User user) {

        System.out.println(user);

        if(user.getId() == null) {
            user.setId(IdWorker.getId()); // MyBatis-Plus提供的分布式ID生成器
        }
        userMapper.insert(user);

        return Result.success("添加用户成功");
    }
}
